﻿using System.Windows.Input;
using Present.Commands.Decorators;

namespace Present.Commands.Fluent
{
    public static class CommandExtensions
    {
        /// <summary>
        /// Schedule the Command to Repeat at an interval
        /// </summary>
        public static ScheduledCommandBuilder<TCommand, TParameter> Schedule<TCommand, TParameter>(this TCommand command) where TCommand : ICommand
        {
            return new ScheduledCommandBuilder<TCommand, TParameter>(command);
        }

        /// <summary>
        /// Schedule the Command to Repeat at an interval
        /// </summary>
        public static ScheduledCommandBuilder<TCommand, object> Schedule<TCommand>(this TCommand command) where TCommand : ICommand
        {
            return new ScheduledCommandBuilder<TCommand, object>(command);
        }

        /// <summary>
        /// Makes the command implement ISelectableCommand
        /// </summary>
        public static SelectableCommandDecorator<TCommand> Selectable<TCommand>(this TCommand command, string name, bool selected) where TCommand : ICommand
        {
            return new SelectableCommandDecorator<TCommand>(command) { Name=name, IsSelected = selected};
        }


        /// <summary>
        /// Binds CanExecuteChanged to CommandManager.RequerySuggested so your CanExecute method is rechecked each time.
        /// Useful when you don't know if your dependent state has changed
        /// </summary>
        public static RequeryCommandDecorator<TCommand> SuggestRequery<TCommand>(this TCommand command) where TCommand : ICommand
        {
            return new RequeryCommandDecorator<TCommand>(command);
        }
    }
}